﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.DemandPlan
{
    public partial class BidPlanManager : System.Web.UI.Page
    {
        Maticsoft.BLL.workFlow wm = new Maticsoft.BLL.workFlow();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDDL();
            }
        }

        //分发招标商务
        protected void btn_ff_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                if (this.ddl_zbsw.SelectedValue == "-1")
                {
                    Maticsoft.Common.MessageBox.Show(this.Page,"请选择分发商务");
                    return;
                }

                int dpid = Convert.ToInt32(Request["id"]);
                List<Maticsoft.Model.documentFlowInfo> li = new Maticsoft.BLL.documentFlowInfo().GetModelList(" document_id = " + dpid);

                if (li.Count == 1)
                {
                    Maticsoft.Model.documentFlowInfo d = li[0];

                    string reason = "同意";
                    int person_id = 0;
                    if (Session["login"] != null)
                    {
                        DataSet ds = Session["login"] as DataSet;

                        person_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"]);
                    }

                    //获取当前审批人审批节点号，transfer的undefine4记录的是该由哪个审批人审批的节点号，如果要修改自身的workFlow，则节点号就是undefine4
                    int flow_node_num_now = Convert.ToInt32(d.flow_node_num_now);
                    int flow_node_id_now = 0;

                    flow_node_id_now = wm.GetFlow_node_id_now(person_id, d.document_id.Value, flow_node_num_now);

                    if (wm.UpdateW(person_id, d.document_id.Value, 1, reason, DateTime.Now, flow_node_id_now, flow_node_num_now))//修改本身意见为同意,添加处理意见、处理时间
                    {
                        int flow_node_id = wm.GetFlow_node_id(person_id, d.document_id.Value, Convert.ToInt32(d.flow_node_num_now),d.flow_id.Value);

                        lcs.BLL.Tools.DealWorkFlowSend(d, flow_node_id, int.Parse(this.ddl_zbsw.SelectedValue), person_id);//分发是属于非会签非尾结点


                    }

                    Response.Redirect("ListBidPlanManager.aspx");
                }
            }
        }

        private void BindDDL()
        {
            DataSet ds = new lcs.BLL.user().GetList(" roles_id=28 ");//公司商务id为28

            this.ddl_zbsw.DataSource = ds;
            this.ddl_zbsw.DataTextField = "user_name";
            this.ddl_zbsw.DataValueField = "user_id";          
            this.ddl_zbsw.DataBind();

            this.ddl_zbsw.Items.Insert(0,new ListItem("--未选择--","-1"));
            
        }
    }
}